package com.example.magichealth;

import java.util.ArrayList;

import com.function.magichealth.FileAndroid;
import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class AMnom extends FileAndroid {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_amnom);
		//Intent venant d'AjoutMedicament 
				Intent intent = new  Intent();
				intent.getComponent();
	}

	public void goToMainScanBar(View view) {
		//Intent intent = new Intent(this, MainScanBar.class);
		//startActivity(intent);
		//instantiate ZXing integration class
		IntentIntegrator scanIntegrator = new IntentIntegrator(this);
		//start scanning
		scanIntegrator.initiateScan();
		
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		//retrieve result of scanning - instantiate ZXing object
		IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
		//check we have a valid result
		if (scanningResult != null) {
			//get content from Intent Result
			String scanContent = scanningResult.getContents();
			//get format name of data scanned
			String scanFormat = scanningResult.getFormatName();
			
			ArrayList<String> scanResults = new ArrayList<String>();
			
			scanResults.add(scanContent);
			scanResults.add(scanFormat);
			super.writeFile(scanResults,"scan_results");
			
			//output to UI
			//formatTxt.setText("FORMAT: "+scanFormat);
			//contentTxt.setText("CONTENT: "+scanContent);
		}
		else{
			//invalid scan data or scan canceled
			Toast toast = Toast.makeText(getApplicationContext(), 
					"No scan data received!", Toast.LENGTH_SHORT);
			toast.show();
		}
	}

	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.amnom, menu);
		return true;
	}
	
	

}
